package com.lucy.starter.auto;

import cn.hutool.core.lang.Validator;
import com.lucy.starter.loader.ModuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.util.List;
import java.util.Map;

@Slf4j
@Configuration
@ComponentScan(basePackages = {
        "com.lucy.starter"
})
public class LucyAutoConfiguration implements EnvironmentAware {
    // 引人模块查询
    @Autowired(required = false)
    List<ModuleService> modules;

    @Override
    public void setEnvironment(Environment environment) {
        StringBuilder logStr = new StringBuilder("lucy-spring-boot-starter v1.0.0\n");
        if (Validator.isNotEmpty(modules)){
            for (ModuleService service:modules){
                logStr.append(service.moduleName()).append(" ").append(service.moduleVersion()).append("\n");
            }
        }

        log.info(
                "\n-------------------------------------\n"
                +logStr
                +"-------------------------------------"
        );
    }
}
